package com.bdqn.pojo;


import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import jakarta.persistence.*;
import lombok.Data;

import java.io.Serial;
import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

@Data
@TableName("sys_role")
public class Role implements Serializable {
  @Serial
  private static final long serialVersionUID = 1L;

  @TableId(type = IdType.AUTO)
  @TableField("role_id")
  private long roleId;

  @TableField("role_name")
  private String roleName;

  @TableField("role_desc")
  private String roleDesc;

  @TableField("role_flag")
  private long roleFlag;

  @OneToMany(targetEntity = User.class,fetch = FetchType.LAZY,cascade = CascadeType.REMOVE,mappedBy = "role")
  private Set<User> users=new HashSet<User>();

  // 多对多
  @ManyToMany(targetEntity = Right.class,fetch = FetchType.LAZY)
  @JoinTable(name = "sys_right",joinColumns = {@JoinColumn(name = "role_id")},inverseJoinColumns = {@JoinColumn(name =  "right_parent_code" )})
  @OrderBy
  private Set<Right> rights=new HashSet<Right>(0);
}
